package module.building.view.produceweapon
{
	import com.darwin.darwinUI.controls.Button;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.controls.LabelButton;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.events.MouseEvent;
	
	import module.main.view.ResourceConst;

	public class WeaponProducePanel extends UIComponent
	{
		/**
		 *装备信息 
		 */		
		private var _equipInfoItem:EquipInfoItem;
		private var _produceWeaponNeed:ProduceWeaponNeed;
		/**
		 *背景 
		 */
		private var _equipInfoBg:UIComponent;
		/**
		 *确定按钮 
		 */		
		private var _sureBtn:LabelButton;
		/**
		 *取消按钮 
		 */		
		private var _chanelBtn:LabelButton;
		/**
		 *关闭按钮 
		 */		
		private var _closeBtn:Button;
		/**
		 *标题 
		 */		
		private var _titleBg:UIComponent;
		private var _titleLabel:Label;
		public function WeaponProducePanel(arr:Array)
		{
			_equipInfoItem = new EquipInfoItem(arr);
			_produceWeaponNeed = new ProduceWeaponNeed(arr);
			_sureBtn = new LabelButton();
			_chanelBtn = new LabelButton();
			_closeBtn = new Button();
			_equipInfoBg = new UIComponent;
			_titleLabel = new Label;
			_titleBg = new UIComponent();
			setUi();
		}
		private function setUi():void
		{
			_sureBtn.backgroundSkin = "EditTroop." + ResourceConst.EDIT_BLUE_BUTTON;
			_sureBtn.height = 34.0;
			_sureBtn.width = 82.0;
			
			_closeBtn.backgroundSkin = "EditTroop." + ResourceConst.EDIT_TROOP_COLSE_BUTTON;
			_closeBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			_closeBtn.height = 23.9;
			_closeBtn.width = 25.9;
			
			_chanelBtn.backgroundSkin = "EditTroop." + ResourceConst.EDIT_TROOP_CHANNEL_BUTTON;
			_sureBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			_chanelBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			_chanelBtn.height = 34.0;
			_chanelBtn.width = 82.0;
			
			_equipInfoBg.backgroundSkin = "EditTroop." + ResourceConst.EDIT_TROOP_BACKGROUND;
			_equipInfoBg.height = 445.8;
			_equipInfoBg.width = 449.1;
			
			_titleBg.backgroundSkin = "EditTroop." + ResourceConst.EDIT_TROOP_TEXTINPUT_PANEL;
			_titleBg.height = 55.0;
			_titleBg.width = 189.9;
			this.height = 445.8 + _titleBg.height / 2;
			this.width = 449.1;
			
			_titleLabel.text = "装备生产";
			setUIPosition();
		}
		private function clickHandler(e:MouseEvent):void
		{
			switch(e.currentTarget)
			{
				case _sureBtn:
					UIManager.getPopUpManager().removePopUp(this);
					break;
				case _chanelBtn:
					UIManager.getPopUpManager().removePopUp(this);
					break;
				case _closeBtn:
					UIManager.getPopUpManager().removePopUp(this);
					break;
			}
		}
		private function setUIPosition():void
		{
			_equipInfoBg.y = _titleBg.height /2;
			addChild(_equipInfoBg);
			
			_titleBg.x = (_equipInfoBg.width - _titleBg.width) / 2;
			_titleBg.y = 10;
			_titleLabel.x = (_titleBg.width - _titleLabel.width) / 2;
			_titleLabel.y = (_titleBg.height - _titleLabel.height) / 2;
			addChild(_titleBg);
			_titleBg.addChild(_titleLabel);
			
			_equipInfoItem.x =  (_equipInfoBg.width - _equipInfoItem.width) / 2;
			_equipInfoItem.y = _titleBg.height + 10;
			addChild(_equipInfoItem);
			
			_produceWeaponNeed.x = 15;
			_produceWeaponNeed.y = _equipInfoItem.y + _equipInfoItem.height + 10;
			addChild(_produceWeaponNeed);
			
			_sureBtn.x = 130;
			_sureBtn.y = 418;
			var la:Label = new Label;
			_sureBtn.text = "确定";
			la.text = _sureBtn.text;
			_sureBtn.textX = (_sureBtn.width - la.width) / 2;
			_sureBtn.textY =  (_sureBtn.height - la.height) / 2;
			addChild(_sureBtn);
			
			_chanelBtn.x = _sureBtn.x + _sureBtn.width + 50;
			_chanelBtn.y = _sureBtn.y;
			addChild(_chanelBtn);
			
			_closeBtn.x = _equipInfoBg.width - _closeBtn.width - 15;
			_closeBtn.y = _closeBtn.height + 15;
			addChild(_closeBtn);
		}
	}
}